package poi;

import java.util.regex.Matcher;

/**
 * 行程安排 2021 版 解析
 *
 * @author likai
 */
public class ParseDocx2Itinerary2021 extends BaseDocumentParse<Itinerary> {

    private static final ParseDocx2Itinerary2021 INSTANCE = new ParseDocx2Itinerary2021();

    private ParseDocx2Itinerary2021(){}

    public static ParseDocx2Itinerary2021 getInstance(){
        return INSTANCE;
    }

    @Override
    public Itinerary parseDocxParagraph(final String paragraph, final TempScanData tempScanData) {
        boolean isNotMatch = "".equals(paragraph) || "\n".equals(paragraph) || "\t".equals(paragraph);
        if (isNotMatch) {
            // data1 为 日期; date2 为 上下午
            return null;
        }
        // 日期 格式：x月x日（可选补充内容，例如星期几）
        Matcher matcher = super.patternList.get(0).matcher(paragraph);
        // 若不符合匹配条件
        final Itinerary itinerary;
        final int i = nextPosition();
        final int j = nextPosition();
        final int k = nextPosition();
        final int m = nextPosition();
        if (matcher.matches()) {
            final String date = matcher.group(i);
            if (date != null) {
                // 上下午 赋值
                tempScanData.data1 = RegUtils.replaceAllSpace(date);
                tempScanData.data2 = RegUtils.replaceAllSpace(matcher.group(j));
            }
            itinerary = null;
        } else {
            matcher = super.patternList.get(1).matcher(paragraph);
            if (!matcher.matches()) {
                itinerary = null;
            } else {
                itinerary = new Itinerary();
                itinerary.setDate(tempScanData == null ? null : tempScanData.data1);
                itinerary.setNoon(tempScanData == null ? null : tempScanData.data2);
                itinerary.setTime(matcher.group(k));
                itinerary.setActivity(matcher.group(m));
            }
        }
        return itinerary;
    }
}
